<?php
include('../../include/functions.inc.php');
$list = $db->query_select("cllg_career", "FK_ENTITY=" . $user->entity);
$listCycles = $db->query_select("cllg_college_cycle", "FK_ENTITY=" . $user->entity);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Asignacion de Estudiantes</title>
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../js/TableOrderer.js" type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <style type="text/css">
            input,
            textarea{
                width: 300px;
            }
            select{
                width: 315px;
            }
        </style>
        <script type="text/javascript">
            var cargos=null;

            datosCarrera=function(control){
                if(control.selectedIndex>0){
                    var pars="CARRERA="+$F("CARRERA");
                    waitMsg("Cargando pensums...");
                    new Ajax.Updater("combo","pensums.php",{parameters:pars,onComplete:function(){
                            closeWait();
                        }});
                }								 
            }
            showCursos=function(control){
                if(control.selectedIndex>0){
                    var pars="PENSUM="+control.value;
                    waitMsg("Cargando cursos...");
                    new Ajax.Updater("cursos","cursos.php",{parameters:pars,onComplete:function(){
                            closeWait();
                        }});
                }
            }


            showCargos=function(){
                new TableOrderer('cargos',{data:cargos});
            }

            datosEstud=function(e){
                $('operation').value=(e.id==2)?'aiu':'id';
                $(document.ASIGNACION).request({onComplete:function(r){
                        res=r.responseJSON;
                        if(res.ERROR){
                            alert(res.ERROR);
                        }else{
                            $('NAME').value=res.NAME;
                            $('ID').value=res.ID;
                            $('AIU_CODE').value=res.AIU;		
                        }
                    }});
            }
            var rsv;
            config=function(){ 
                rsv=new RSV({
                    formID: $(document.ASIGNACION),
                    errorFieldClass: "errorField",
                    rules: ["required,NAME,Debe buscar un estudiante!"],
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212; ",
                    onCompleteHandler:function(){
                        $('operation').value='prev';
                        $(document.ASIGNACION).request({onComplete:function(r){
                                alert(r.responseText);
                                if(r.responseJSON.ST==1){
                                    $('operation').value='s';
                                    $(document.ASIGNACION).submit();
                                }else{
                                    alert(r.responseJSON.ERROR);
                                }
                            }});
							
                    }});
            }

            addOnLoad(config);

        </script>
    </head>

    <body>
        <div id="rsvErrors"></div>
        <form id="ASIGNACION" name="ASIGNACION" method="GET" action="data.php">
            <table class="tableform"  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th scope="col">ASIGNACION DE CURSOS</th>
                    <th scope="col">
                        <input type="button" name="cmdOk" id="cmdOk" class="btnOk" onClick="rsv.validate();" /></th>
                </tr>
                <tr>
                    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="25%"> NO. CARNET</td>
                                <td width="75%">&nbsp;</td>
                            </tr>


                            <tr>
                                <td>NOMBRE ESTUDIANTE</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>CARRERA</td>
                                <td><select name="CARRERA" id="CARRERA" onchange="datosCarrera(this);">
                                        <option value="">Seleccione</option>
                                        <?php foreach ($list as $it) { ?>
                                            <option value="<?php echo $it["ID"]; ?>"><?php echo $it["NAME"]; ?> </option>
                                        <?php } ?>
                                    </select>          </td>
                            </tr>
                            <tr>
                                <td>PENSUM</td>
                                <td id="combo"><select name="PENSUM" id="PENSUM" onchange="showCursos();">
                                        <option value=" " selected="selected">-Seleccionar-</option>
                                    </select>          </td>
                            </tr>
                            <tr>
                                <td>CICLO</td>
                                <td><select name="CYCLE" id="CYCLE">
                                        <option value="">Seleccione</option>
                                        <?php foreach ($listCycles as $it) { ?>
                                            <option value="<?php echo $it["CODE"]; ?>"><?php echo $it["CODE"]; ?> </option>
                                        <?php } ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <td colspan="2"><div id="cursos" style="width:700px;"></div></td>
                            </tr>

                        </table></td>
                </tr>
                <tr>
                    <td colspan="2"><input name="CICLO" type="hidden" id="CICLO" value="<?php echo $user->cycle; ?>" />
                        <input type="hidden" name="operation" id="operation" /></td>
                </tr>
            </table>
        </form>

    </body>
</html>
